package com.market.controller;

import com.market.common.exception.ControllerException;
import com.market.common.vo.ResponseCode;
import com.market.common.vo.ResponseResult;
import com.market.entity.CommercialTenant;
import com.market.service.CommercialTenantService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/commercial/tenant")
public class CommercialTenantContorller {
    @Resource
    CommercialTenantService commercialTenantService;

    /**
     * 新增
     *
     * @param commercialTenant
     * @return
     * @throws ControllerException
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody CommercialTenant commercialTenant) throws ControllerException {
        int i = commercialTenantService.addCommercialTenant(commercialTenant);
        return ResponseResult.success(ResponseCode.SUCCESS, i);
    }

    /**
     * 删除
     *
     * @param commercialTenantId
     * @return
     * @throws ControllerException
     */
    @GetMapping("/del")
    public ResponseResult<Integer> del(@RequestParam Long commercialTenantId) throws ControllerException {
        int i = commercialTenantService.delCommercialTenant(commercialTenantId);
        return ResponseResult.success(ResponseCode.SUCCESS, i);
    }


    /**
     * 查询
     *
     * @return
     * @throws ControllerException
     */
    @GetMapping("/find")
    public ResponseResult<List<CommercialTenant>> find() throws ControllerException {
        List<CommercialTenant> commercialTenant = commercialTenantService.findCommercialTenant();
        return ResponseResult.success(ResponseCode.SUCCESS, commercialTenant);
    }
}
